#pragma once


template<typename T> class AutoDelete
{
	T *p;
public:
	inline AutoDelete(): p(0) { }
	inline AutoDelete(T *ptr): p(ptr) { }
	inline ~AutoDelete() { if(p) delete p; }
	inline operator T*() const { return p; }
	inline T& operator *() { return *p; }
	inline T* operator ->() { return p; }
	inline const T* operator ->() const { return p; }
	inline T& operator[](int index) { return p[index]; }
	inline T* operator =(T* other) { if(p) delete p; p = other; return p; }
	/// Return the pointer and don't delete it.
	inline T* dontDelete() { T* orgP = p; p = 0; return orgP; }
	inline T* getPointer() { return p; }
};

template<typename T> class AutoDeleteArray
{
	T *p;
public:
	inline AutoDeleteArray(): p(0) { }
	inline AutoDeleteArray(T *ptr): p(ptr) { }
	inline ~AutoDeleteArray() { if(p) delete[] p; }
	inline operator T*() const { return p; }
	inline T& operator *() { return *p; }
	inline T* operator ->() { return p; }
	inline const T* operator ->() const { return p; }
	inline T& operator[](int index) { return p[index]; }
	inline T* operator =(T* other) { if(p) delete[] p; p = other; return p; }
	/// Return the pointer and don't delete it.
	inline T* dontDelete() { T* orgP = p; p = 0; return orgP; }
	inline T* getPointer() { return p; }
};

